package com.moonLight.weblog.admin.controller;


import com.moonLight.weblog.admin.model.vo.tag.*;
import com.moonLight.weblog.admin.service.AdminTagService;
import com.moonLight.weblog.common.aspect.ApiOperationLog;
import com.moonLight.weblog.common.utils.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/admin")
@Api(tags = "Admin 标签模块")
public class AdminTagController {
    @Autowired
    private AdminTagService adminTagService;


    @PostMapping("/tag/add")
    @ApiOperation(value = "添加标签")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    @ApiOperationLog(description = "添加标签")
    public Response<Void> saveTag(@RequestBody @Validated AddTagVo addTagVo ) {
        return adminTagService.addTag(addTagVo);
    }

    @PostMapping("/tag/list")
    @ApiOperation(value = "获取标签列表 分页")
    @ApiOperationLog(description = "获取标签列表 分页")
    public Response<List<FindTagPageListRspVo>> findTagPageList(@RequestBody @Validated FindTagPageListReqVo findTagPageListReqVo) {
        return adminTagService.findTagPageList(findTagPageListReqVo);
    }


    @PostMapping("/tag/delete")
    @ApiOperation(value = "删除标签")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    @ApiOperationLog(description = "删除标签")
    public Response<Void> deleteTag(@RequestBody @Validated DeleteTagReqVO findTagPageListReqVo) {
        return adminTagService.deleteTag(findTagPageListReqVo);
    }

    @PostMapping("/tag/select/list")
    @ApiOperation(value = "分类 Select 下拉列表数据获取")
    @ApiOperationLog(description = "分类 Select 下拉列表数据获取")
    public Response<List<TagVo>> findCategorySelectList() {
        return adminTagService.findTagSelectList();
    }

    @PostMapping("/tag/search")
    @ApiOperation(value = "标签搜索")
    @ApiOperationLog(description = "标签搜索")
    public Response<List<String>> searchTag(@RequestBody @Validated SearchTagReqVo searchTagReqVo) {
        return adminTagService.searchTag(searchTagReqVo);
    }



}
